{include file="common_top.html"}
	{include file="common_head.html"}
	<style type="text/css">
	{literal}
		.datatable.list .data table input{width:100%;margin:2px 0px;}
		.datatable.list .data table .tr{text-align:right;}
	{/literal}
	</style>
</head>
<body class="mainbody">
	<div class="datatable">
		<div class="data"><table><tbody>
			<tr class="nobb"><td class="filter">
				<label>分类</label><input type="text" class="txt au_keyword" />
				<label>路径</label><input type="text" class="txt w250 au_path" />
				<label>地址</label><input type="text" class="txt w250 au_url" />
			</td><td class="w50">
				<input type="button" data-id="0" class="btn btn_edit" value="添加" />
			</td></tr>
		</tbody></table></div>
	</div>
	{foreach from=$objects.data key=k item=cate}
		<div class="datatable">
		<h3>{$k}</h3>
		<div class="data"><table><tbody>
			{foreach from=$cate item=object}
				{include file="autoupdate_list_block.html"}
			{/foreach}
		</tbody></table></div>
		</div>
	{/foreach}
	<div class="msgdialog"></div>
	<script type="text/javascript">
	{literal}
		$("body").on("click", ".btn_edit", function(){
			var id = $(this).data("id");
			var that = this;
			var obj = $(this).parent().parent();
			if(id > 0){
				data = {id: id, type: "edit", url: obj.find(".au_url").val()};
			}else{
				data = {id: id, type: "edit", keyword: obj.find(".au_keyword").val(), path: obj.find(".au_path").val(), url: obj.find(".au_url").val()};
			}
			$.ajax({type: "POST", dataType: "JSON", url: "/index.php?a=autoupdate&m=operate&t=ajax", data: data, async: false, success: function(result){
				if(result.state){
					$(".msgdialog").html(result.message).dialog({modal: true, buttons: {Ok: function(){
						$(this).dialog("close");
						if(id > 0){
							$(".tr_" + id).addClass("tr_id_del").after(result.data);
							$(".tr_id_del").remove();
						}else{
							window.location.href = window.location.href;
						}
					}}});
				}else{
					$(".msgdialog").html(result.message).dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
				}
			}, error: function(jqXHR, textStatus, errorThrown){
				$(".msgdialog").html("AJAX请求出错[" + errorThrown + "].").dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
			}});
		});
		$("body").on("click", ".btn_upd", function(){
			var id = $(this).data("id");
			var that = this;
			$.ajax({type: "POST", dataType: "JSON", url: "/index.php?a=autoupdate&m=operate&t=ajax", data: {id: id, type: "upd"}, async: false, success: function(result){
				if(result.state){
					$(".tr_" + id).addClass("tr_id_del").after(result.data);
					$(".tr_id_del").remove();
				}else{
					$(".msgdialog").html(result.message).dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
				}
			}, error: function(jqXHR, textStatus, errorThrown){
				$(".msgdialog").html("AJAX请求出错[" + errorThrown + "].").dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
			}});
		});
		$("body").on("click", ".btn_del", function(){
			var id = $(this).data("id");
			var that = this;
			$(".msgdialog").attr("title", "确认").html($(this).data("confirm")).dialog({
				modal: true, buttons: {
					Ok: function(){
						var thatthat = this;
						$.ajax({type: "POST", dataType: "JSON", url: "/index.php?a=autoupdate&m=operate&t=ajax", data: {id: id, type: "del"}, async: false, success: function(result){
							$(thatthat).dialog("close");
							if(result.state){
								$(that).parent().parent().remove();
							}else{
								$(".msgdialog").html(result.message).dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
							}
						}, error: function(jqXHR, textStatus, errorThrown){
							$(thatthat).dialog("close");
							$(".msgdialog").html("AJAX请求出错[" + errorThrown + "].").dialog({modal: true, buttons: {Cancel: function(){$(this).dialog("close");}}});
						}});
					},
					Cancel: function(){
						$(this).dialog("close");
					}
				}
			});
		});
	{/literal}
	</script>
{include file="common_copyright.html"}
{include file="common_bottom.html"}
